package cn.edu.sgu.www.mhxysy.controller.except;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.except.Property;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.except.PropertyService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/property", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class PropertyController {

	private final PropertyService propertyService;

	@Autowired
	public PropertyController(PropertyService propertyService) {
		this.propertyService = propertyService;
	}

	@ApiOperation("查询全部属性")
	@RequestMapping(value = "/selectAll", method = RequestMethod.GET)
	public JsonResult<List<Property>> selectAll() {
		List<Property> list = propertyService.selectAll();

		return JsonResult.success(null, list);
	}

	@ApiOperation("通过ID查询属性")
	@RequestMapping(value = "/selectById", method = RequestMethod.GET)
	public JsonResult<Property> selectById(
			@ApiParam(name = "id", value = "属性ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		Property property = propertyService.selectById(id);

		return JsonResult.success(null, property);
	}

	@ApiOperation("根据类型查询属性列表")
	@RequestMapping(value = "/selectByType", method = RequestMethod.GET)
	public JsonResult<List<Property>> selectByType(
			@ApiParam(name = "type", value = "属性类型", required = true)
			@NotNull(message = "属性类型" + CustomMessages.NOT_NULL) Integer type) {
		List<Property> list = propertyService.selectByType(type);

		return JsonResult.success(null, list);
	}

}